package exam;

import java.util.HashSet;
import java.util.Set;

/**
 * Tests the answer to the first set question.
 * The text of the question is as follows:
 * "Write a method that returns the union of two Set<E> instances without altering the original 
 *  Sets."
 * 
 * @author Branden Ogata
 *
 */

public class TestSetA00 extends Tester
{
  public static void main(String[] args)
  {
    final double POINTS = getPoints(args);

    Set<Integer> left = new HashSet<Integer>();
    Set<Integer> right = new HashSet<Integer>();
    Set<Integer> results = new HashSet<Integer>();
    
    System.out.println(test(Category.EQUALS, "union([], [])", 
                            results, SetA00.union(left, right), 
                            percentageToPoints(TWELFTH, POINTS)));
    left.clear(); 
    right.clear();
    results.clear();
    
    left.add(1);
    results.add(1);
    System.out.println(test(Category.EQUALS, "union([1], [])", 
                            results, SetA00.union(left, right), 
                            percentageToPoints(TWELFTH, POINTS)));
    left.clear(); 
    right.clear();
    results.clear();
    
    right.add(2);
    results.add(2);
    System.out.println(test(Category.EQUALS, "union([], [2])", 
                            results, SetA00.union(left, right), 
                            percentageToPoints(TWELFTH, POINTS)));
    left.clear(); 
    right.clear();
    results.clear();
    
    left.add(3);
    right.add(4);
    results.add(3);
    results.add(4);
    System.out.println(test(Category.EQUALS, "union([3], [4])", 
                            results, SetA00.union(left, right), 
                            percentageToPoints(TWELFTH, POINTS)));
    left.clear(); 
    right.clear(); 
    results.clear();
        
    left.add(7);
    left.add(9);
    right.add(8);
    results.add(7);
    results.add(9);
    results.add(8);
    System.out.println(test(Category.EQUALS, "union([7, 9], [8])", 
                            results, SetA00.union(left, right), 
                            percentageToPoints(TWELFTH, POINTS)));
    left.clear(); 
    right.clear(); 
    results.clear();
    
    left.add(2);
    right.add(0);
    right.add(1);
    results.add(2);
    results.add(0);
    results.add(1);
    System.out.println(test(Category.EQUALS, "union([2], [0, 1])", 
                            results, SetA00.union(left, right), 
                            percentageToPoints(TWELFTH, POINTS)));
    left.clear(); 
    right.clear();    
    results.clear();
    
    left.add(3);
    left.add(5);
    right.add(4);
    right.add(6);
    results.add(3);
    results.add(4);
    results.add(5);
    results.add(6);
    System.out.println(test(Category.EQUALS, "union([3, 5], [4, 6])", 
                            results, SetA00.union(left, right), 
                            percentageToPoints(TWELFTH, POINTS)));
    left.clear(); 
    right.clear();    
    results.clear();
    
    left.add(1);
    right.add(1);
    results.add(1);
    System.out.println(test(Category.EQUALS, "union([1], [1])", 
                            results, SetA00.union(left, right), 
                            percentageToPoints(TWELFTH, POINTS)));
    left.clear(); 
    right.clear();    
    results.clear();    

    left.add(1);
    left.add(2);
    left.add(4);
    left.add(8);
    right.add(1);
    right.add(2);
    right.add(3);
    right.add(5);
    right.add(8);
    Set<Integer> leftCopy = new HashSet<Integer>(left);
    Set<Integer> rightCopy = new HashSet<Integer>(right);
    results.add(1);
    results.add(2);
    results.add(3);
    results.add(4);
    results.add(5);
    results.add(8);
    System.out.println(test(Category.EQUALS, "union([1, 2, 4, 8], [1, 2, 3, 5, 8])", 
                            results, SetA00.union(left, right), 
                            percentageToPoints(TWELFTH, POINTS)));
    System.out.println(test(Category.EQUALS, "union([1, 2, 4, 8], [1, 2, 3, 5, 8]); " + 
                                             "Left child unchanged", 
                            leftCopy, left, 
                            percentageToPoints(TWELFTH, POINTS)));
    System.out.println(test(Category.EQUALS, "union([1, 2, 4, 8], [1, 2, 3, 5, 8]); " + 
                                             "Right child unchanged", 
                            rightCopy, right, 
                            percentageToPoints(TWELFTH, POINTS)));
    
    left.clear(); 
    right.clear();  
    leftCopy.clear();
    rightCopy.clear();
    results.clear();
    
    Set<String> leftStringSet = new HashSet<String>();
    Set<String> rightStringSet = new HashSet<String>();
    Set<String> resultsStringSet = new HashSet<String>();
    leftStringSet.add("alpha");
    leftStringSet.add("beta");
    leftStringSet.add("gamma");
    leftStringSet.add("delta");
    rightStringSet.add("omega");
    rightStringSet.add("gamma");
    rightStringSet.add("alpha");
    rightStringSet.add("beta");
    resultsStringSet.add("omega");
    resultsStringSet.add("gamma");
    resultsStringSet.add("alpha");
    resultsStringSet.add("beta");
    resultsStringSet.add("delta");

    System.out.println(test(Category.EQUALS, "union([\"alpha\", \"beta\", \"gamma\", \"delta\"], " +
                                                   "[\"omega\", \"gamma\", \"alpha\", \"beta\"])", 
                            resultsStringSet, SetA00.union(leftStringSet, rightStringSet), 
                            percentageToPoints(TWELFTH, POINTS)));
    left.clear(); 
    right.clear();    
    results.clear();
    
    System.out.format("[%.2f/%.2f]%n", getTotalPoints(), POINTS);
  }
}
